/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package de.hsmannheim.pepa.patientenportal.apanwep.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import de.hsmannheim.pepa.patientenportal.apanwep.service.ClpSerializer;
import de.hsmannheim.pepa.patientenportal.apanwep.service.message_participantsLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Cedric Nana
 */
public class message_participantsClp extends BaseModelImpl<message_participants>
	implements message_participants {
	public message_participantsClp() {
	}

	@Override
	public Class<?> getModelClass() {
		return message_participants.class;
	}

	@Override
	public String getModelClassName() {
		return message_participants.class.getName();
	}

	@Override
	public long getPrimaryKey() {
		return _ID;
	}

	@Override
	public void setPrimaryKey(long primaryKey) {
		setID(primaryKey);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return _ID;
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("ID", getID());
		attributes.put("Participant_Id", getParticipant_Id());
		attributes.put("Networkaccesspoint_Id", getNetworkaccesspoint_Id());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long ID = (Long)attributes.get("ID");

		if (ID != null) {
			setID(ID);
		}

		Long Participant_Id = (Long)attributes.get("Participant_Id");

		if (Participant_Id != null) {
			setParticipant_Id(Participant_Id);
		}

		Long Networkaccesspoint_Id = (Long)attributes.get(
				"Networkaccesspoint_Id");

		if (Networkaccesspoint_Id != null) {
			setNetworkaccesspoint_Id(Networkaccesspoint_Id);
		}
	}

	@Override
	public long getID() {
		return _ID;
	}

	@Override
	public void setID(long ID) {
		_ID = ID;

		if (_message_participantsRemoteModel != null) {
			try {
				Class<?> clazz = _message_participantsRemoteModel.getClass();

				Method method = clazz.getMethod("setID", long.class);

				method.invoke(_message_participantsRemoteModel, ID);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public long getParticipant_Id() {
		return _Participant_Id;
	}

	@Override
	public void setParticipant_Id(long Participant_Id) {
		_Participant_Id = Participant_Id;

		if (_message_participantsRemoteModel != null) {
			try {
				Class<?> clazz = _message_participantsRemoteModel.getClass();

				Method method = clazz.getMethod("setParticipant_Id", long.class);

				method.invoke(_message_participantsRemoteModel, Participant_Id);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public long getNetworkaccesspoint_Id() {
		return _Networkaccesspoint_Id;
	}

	@Override
	public void setNetworkaccesspoint_Id(long Networkaccesspoint_Id) {
		_Networkaccesspoint_Id = Networkaccesspoint_Id;

		if (_message_participantsRemoteModel != null) {
			try {
				Class<?> clazz = _message_participantsRemoteModel.getClass();

				Method method = clazz.getMethod("setNetworkaccesspoint_Id",
						long.class);

				method.invoke(_message_participantsRemoteModel,
					Networkaccesspoint_Id);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public BaseModel<?> getmessage_participantsRemoteModel() {
		return _message_participantsRemoteModel;
	}

	public void setmessage_participantsRemoteModel(
		BaseModel<?> message_participantsRemoteModel) {
		_message_participantsRemoteModel = message_participantsRemoteModel;
	}

	public Object invokeOnRemoteModel(String methodName,
		Class<?>[] parameterTypes, Object[] parameterValues)
		throws Exception {
		Object[] remoteParameterValues = new Object[parameterValues.length];

		for (int i = 0; i < parameterValues.length; i++) {
			if (parameterValues[i] != null) {
				remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
			}
		}

		Class<?> remoteModelClass = _message_participantsRemoteModel.getClass();

		ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

		Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

		for (int i = 0; i < parameterTypes.length; i++) {
			if (parameterTypes[i].isPrimitive()) {
				remoteParameterTypes[i] = parameterTypes[i];
			}
			else {
				String parameterTypeName = parameterTypes[i].getName();

				remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
			}
		}

		Method method = remoteModelClass.getMethod(methodName,
				remoteParameterTypes);

		Object returnValue = method.invoke(_message_participantsRemoteModel,
				remoteParameterValues);

		if (returnValue != null) {
			returnValue = ClpSerializer.translateOutput(returnValue);
		}

		return returnValue;
	}

	@Override
	public void persist() throws SystemException {
		if (this.isNew()) {
			message_participantsLocalServiceUtil.addmessage_participants(this);
		}
		else {
			message_participantsLocalServiceUtil.updatemessage_participants(this);
		}
	}

	@Override
	public message_participants toEscapedModel() {
		return (message_participants)ProxyUtil.newProxyInstance(message_participants.class.getClassLoader(),
			new Class[] { message_participants.class },
			new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		message_participantsClp clone = new message_participantsClp();

		clone.setID(getID());
		clone.setParticipant_Id(getParticipant_Id());
		clone.setNetworkaccesspoint_Id(getNetworkaccesspoint_Id());

		return clone;
	}

	@Override
	public int compareTo(message_participants message_participants) {
		long primaryKey = message_participants.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof message_participantsClp)) {
			return false;
		}

		message_participantsClp message_participants = (message_participantsClp)obj;

		long primaryKey = message_participants.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(7);

		sb.append("{ID=");
		sb.append(getID());
		sb.append(", Participant_Id=");
		sb.append(getParticipant_Id());
		sb.append(", Networkaccesspoint_Id=");
		sb.append(getNetworkaccesspoint_Id());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(13);

		sb.append("<model><model-name>");
		sb.append(
			"de.hsmannheim.pepa.patientenportal.apanwep.model.message_participants");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>ID</column-name><column-value><![CDATA[");
		sb.append(getID());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>Participant_Id</column-name><column-value><![CDATA[");
		sb.append(getParticipant_Id());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>Networkaccesspoint_Id</column-name><column-value><![CDATA[");
		sb.append(getNetworkaccesspoint_Id());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _ID;
	private long _Participant_Id;
	private long _Networkaccesspoint_Id;
	private BaseModel<?> _message_participantsRemoteModel;
}